namespace BITS.PreCompiler.CSharp.Syntax.Extensions
{
    /// <summary>
    /// Extension methods for interface nodes.
    /// </summary>
    public static class InterfaceExtension
    {
        /// <summary>
        /// Implements the specified @this.
        /// </summary>
        /// <param name="this">The @this.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        public static Method ImplementAsMethod(this InterfaceMethod @this, IBaseSyntaxNode parent = null)
        {
            var method = new Method(@this.GetSyntaxNode(), parent, isAbstract: false);
            method.ClearAttributeDeclarations();
            method.MakePublic();

            return method;
        }

        /// <summary>
        /// Implements the specified @this explicit.
        /// </summary>
        /// <param name="this">The @this.</param>
        /// <param name="parent">The parent.</param>
        /// <returns></returns>
        public static Method ImplementAsExplicitMethod(this InterfaceMethod @this, IBaseSyntaxNode parent = null)
        {
            var method = new Method(@this.GetSyntaxNode(), parent, isAbstract: false);
            method.WithExplicitInterface(@this.Parent);
            method.ClearAttributeDeclarations();

            return method;
        }

        /// <summary>
        /// Adds a exception to method body.
        /// </summary>
        /// <param name="this">The @this.</param>
        /// <returns></returns>
        public static Method WithNotImplementedException(this Method @this)
        {
            @this.ClearStatements();

            @this.Add("throw new NotImplementedException();");

            return @this;
        }
    }
}